package com.atguigu.spzx.manager.controller.system;

import com.atguigu.spzx.manager.service.system.SysMenuService;
import com.atguigu.spzx.model.entity.system.SysMenu;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.system.SysMenuVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Mahone
 */
@RestController
@RequestMapping("/admin/system/sysMenu")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    /**
     * 查询菜单列表下的属于角色集合
     * @return
     */
    @GetMapping("/findNodes")
    public Result findNodes(){
        List<SysMenu> sysMenuList = sysMenuService.findNodes();
        return Result.ok(sysMenuList);
    }

    /**
     * 菜单管理添加功能
     * @param sysMenu
     * @return
     */
    @PostMapping("/saveMenu")
    public Result saveMenu(@RequestBody SysMenu sysMenu){
        sysMenuService.saveMenu(sysMenu);
        return Result.ok();
    }


    /**
     * 菜单管理修改功能
     * @param sysMenu
     * @return
     */
    @PutMapping("/updateSysMenuById")
    public Result updateSysMenuById(@RequestBody SysMenu sysMenu){
        sysMenuService.updateSysMenuById(sysMenu);
        return Result.ok();
    }

    /**
     * 删除当前行菜单
     * @return
     */
    @DeleteMapping("/removeSysMenuById/{id}")
    public Result removeSysMenuById(@PathVariable("id") Long id){
        sysMenuService.removeSysMenuById(id);
        return Result.ok();
    }

    /**
     * 动态获取菜单列表
     * @return
     */
    @GetMapping("/menus")
    public Result menus(){
        List<SysMenuVo> sysMenuList = sysMenuService.menus();
        return Result.ok(sysMenuList);
    }
}
